From 925fb508504c3b8c23fe1c951cbd24e8c75ba96f Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Sun, 11 Oct 2015 13:33:55 -0500 Subject: [PATCH] Differentiates documentation and compilation in user output Fix tests to work with new jobqueue --- src/cargo/ops/cargo_rustc/job_queue.rs | 28 +++++++++++------- tests/support/mod.rs | 1 + tests/test_cargo_compile_custom_build.rs | 6 ++-- tests/test_cargo_cross_compile.rs | 36 +++++++++++++----------- tests/test_cargo_doc.rs | 32 +++++++++++---------- 5 files changed, 59 insertions(+), 44 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/job_queue.rs b/src/cargo/ops/cargo_rustc/job_queue.rs index 554889649..5966ca3ed 100644 --- a/src/cargo/ops/cargo_rustc/job_queue.rs +++ b/src/cargo/ops/cargo_rustc/job_queue.rs @@ -25,7 +25,8 @@ pub struct JobQueue<'a> { rx: Receiver>, active: usize, pending: HashMap, PendingBuild>, - printed: HashSet<&'a PackageId>, + compiled: HashSet<&'a PackageId>, + documented: HashSet<&'a PackageId>, counts: HashMap<&'a PackageId, usize>, } @@ -61,7 +62,8 @@ impl<'a> JobQueue<'a> { rx: rx, active: 0, pending: HashMap::new(), - printed: HashSet::new(), + compiled: HashSet::new(), + documented: HashSet::new(), counts: HashMap::new(), } } @@ -181,7 +183,7 @@ impl<'a> JobQueue<'a> { }); // Print out some nice progress information - try!(self.note_working_on(config, key.pkg, fresh)); + try!(self.note_working_on(config, &key, fresh)); // only the first message of each job is processed if let Ok(msg) = desc_rx.recv() { @@ -199,9 +201,10 @@ impl<'a> JobQueue<'a> { // In general, we try to print "Compiling" for the first nontrivial task // run for a package, regardless of when that is. We then don't print // out any more information for a package after we've printed it once. - fn note_working_on(&mut self, config: &Config, pkg: &'a PackageId, + fn note_working_on(&mut self, config: &Config, key: &Key<'a>, fresh: Freshness) -> CargoResult<()> { - if self.printed.contains(&pkg) { + if (self.compiled.contains(key.pkg) && !key.profile.doc) || + (self.documented.contains(key.pkg) && key.profile.doc) { return Ok(()) } @@ -209,12 +212,17 @@ impl<'a> JobQueue<'a> { // Any dirty stage which runs at least one command gets printed as // being a compiled package Dirty => { - self.printed.insert(pkg); - try!(config.shell().status("Compiling", pkg)); + if key.profile.doc { + self.documented.insert(key.pkg); + try!(config.shell().status("Documenting", key.pkg)); + } else { + self.compiled.insert(key.pkg); + try!(config.shell().status("Compiling", key.pkg)); + } } - Fresh if self.counts[pkg] == 0 => { - self.printed.insert(pkg); - try!(config.shell().verbose(|c| c.status("Fresh", pkg))); + Fresh if self.counts[key.pkg] == 0 => { + self.compiled.insert(key.pkg); + try!(config.shell().verbose(|c| c.status("Fresh", key.pkg))); } Fresh => {} } diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 55589f350..38e434870 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -552,6 +552,7 @@ pub fn path2url(p: PathBuf) -> Url { pub static RUNNING: &'static str = " Running"; pub static COMPILING: &'static str = " Compiling"; +pub static DOCUMENTING: &'static str = " Documenting"; pub static FRESH: &'static str = " Fresh"; pub static UPDATING: &'static str = " Updating"; pub static ADDING: &'static str = " Adding"; diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index a28bd4633..e21718a22 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -2,7 +2,7 @@ use std::fs::File; use std::io::prelude::*; use support::{project, execs}; -use support::{COMPILING, RUNNING, DOCTEST, FRESH}; +use support::{COMPILING, RUNNING, DOCTEST, FRESH, DOCUMENTING}; use support::paths::CargoPathExt; use hamcrest::{assert_that}; @@ -506,9 +506,9 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured assert_that(p.cargo("doc").arg("-v"), execs().with_status(0) .with_stdout(&format!("\ -{compiling} foo v0.5.0 (file://[..]) +{documenting} foo v0.5.0 (file://[..]) {running} `rustdoc [..]` -", compiling = COMPILING, running = RUNNING))); +", documenting = DOCUMENTING, running = RUNNING))); File::create(&p.root().join("src/main.rs")).unwrap() .write_all(b"fn main() {}").unwrap(); diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index cb9725763..ca75fac35 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -565,25 +565,29 @@ test!(build_script_needed_for_host_and_target { assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v"), execs().with_status(0) - .with_stdout(&format!("\ -{compiling} d1 v0.0.0 ({url}) -{running} `rustc d1[..]build.rs [..] --out-dir {dir}[..]target[..]build[..]d1-[..]` -{running} `{dir}[..]target[..]build[..]d1-[..]build-script-build` -{running} `{dir}[..]target[..]build[..]d1-[..]build-script-build` -{running} `rustc d1[..]src[..]lib.rs [..]` -{running} `rustc d1[..]src[..]lib.rs [..]` -{compiling} d2 v0.0.0 ({url}) + .with_stdout_contains(&format!("\ +{compiling} d1 v0.0.0 ({url})", compiling = COMPILING, url = p.url())) + .with_stdout_contains(&format!("\ +{running} `rustc d1[..]build.rs [..] --out-dir {dir}[..]target[..]build[..]d1-[..]`", + running = RUNNING, dir = p.root().display())) + .with_stdout_contains(&format!("\ +{running} `{dir}[..]target[..]build[..]d1-[..]build-script-build`", running = RUNNING, + dir = p.root().display())) + .with_stdout_contains(&format!("\ +{running} `rustc d1[..]src[..]lib.rs [..]`", running = RUNNING)) + .with_stdout_contains(&format!("\ +{compiling} d2 v0.0.0 ({url})", compiling = COMPILING, url = p.url())) + .with_stdout_contains(&format!("\ {running} `rustc d2[..]src[..]lib.rs [..] \ - -L /path/to/{host}` -{compiling} foo v0.0.0 ({url}) + -L /path/to/{host}`", running = RUNNING, host = host)) + .with_stdout_contains(&format!("\ +{compiling} foo v0.0.0 ({url})", compiling = COMPILING, url = p.url())) + .with_stdout_contains(&format!("\ {running} `rustc build.rs [..] --out-dir {dir}[..]target[..]build[..]foo-[..] \ - -L /path/to/{host}` -{running} `{dir}[..]target[..]build[..]foo-[..]build-script-build` + -L /path/to/{host}`", running = RUNNING, dir = p.root().display(), host = host)) + .with_stdout_contains(&format!("\ {running} `rustc src[..]main.rs [..] --target {target} [..] \ - -L /path/to/{target}` -", compiling = COMPILING, running = RUNNING, target = target, host = host, - url = p.url(), - dir = p.root().display()))); + -L /path/to/{target}`", running = RUNNING, target = target))); }); test!(build_deps_for_the_right_arch { diff --git a/tests/test_cargo_doc.rs b/tests/test_cargo_doc.rs index 935178379..24628d28a 100644 --- a/tests/test_cargo_doc.rs +++ b/tests/test_cargo_doc.rs @@ -1,7 +1,7 @@ use std::str; use support::{project, execs, path2url}; -use support::{COMPILING, RUNNING}; +use support::{COMPILING, DOCUMENTING, RUNNING}; use hamcrest::{assert_that, existing_file, existing_dir, is_not}; fn setup() { @@ -23,9 +23,9 @@ test!(simple { assert_that(p.cargo_process("doc"), execs().with_status(0).with_stdout(&format!("\ -{compiling} foo v0.0.1 ({dir}) +[..] foo v0.0.1 ({dir}) +[..] foo v0.0.1 ({dir}) ", - compiling = COMPILING, dir = path2url(p.root())))); assert_that(&p.root().join("target/doc"), existing_dir()); assert_that(&p.root().join("target/doc/foo/index.html"), existing_file()); @@ -65,9 +65,9 @@ test!(doc_twice { assert_that(p.cargo_process("doc"), execs().with_status(0).with_stdout(&format!("\ -{compiling} foo v0.0.1 ({dir}) +{documenting} foo v0.0.1 ({dir}) ", - compiling = COMPILING, + documenting = DOCUMENTING, dir = path2url(p.root())))); assert_that(p.cargo("doc"), @@ -101,10 +101,11 @@ test!(doc_deps { assert_that(p.cargo_process("doc"), execs().with_status(0).with_stdout(&format!("\ -{compiling} bar v0.0.1 ({dir}) -{compiling} foo v0.0.1 ({dir}) +[..] bar v0.0.1 ({dir}) +[..] bar v0.0.1 ({dir}) +{documenting} foo v0.0.1 ({dir}) ", - compiling = COMPILING, + documenting = DOCUMENTING, dir = path2url(p.root())))); assert_that(&p.root().join("target/doc"), existing_dir()); @@ -148,9 +149,9 @@ test!(doc_no_deps { assert_that(p.cargo_process("doc").arg("--no-deps"), execs().with_status(0).with_stdout(&format!("\ {compiling} bar v0.0.1 ({dir}) -{compiling} foo v0.0.1 ({dir}) +{documenting} foo v0.0.1 ({dir}) ", - compiling = COMPILING, + documenting = DOCUMENTING, compiling = COMPILING, dir = path2url(p.root())))); assert_that(&p.root().join("target/doc"), existing_dir()); @@ -243,9 +244,10 @@ test!(doc_dash_p { assert_that(p.cargo_process("doc").arg("-p").arg("a"), execs().with_status(0) .with_stdout(&format!("\ -{compiling} b v0.0.1 (file://[..]) -{compiling} a v0.0.1 (file://[..]) -", compiling = COMPILING))); +[..] b v0.0.1 (file://[..]) +[..] b v0.0.1 (file://[..]) +{documenting} a v0.0.1 (file://[..]) +", documenting = DOCUMENTING))); }); test!(doc_same_name { @@ -428,9 +430,9 @@ test!(doc_release { assert_that(p.cargo("doc").arg("--release").arg("-v"), execs().with_status(0) .with_stdout(&format!("\ -{compiling} foo v0.0.1 ([..]) +{documenting} foo v0.0.1 ([..]) {running} `rustdoc src[..]lib.rs [..]` -", compiling = COMPILING, running = RUNNING))); +", documenting = DOCUMENTING, running = RUNNING))); }); test!(doc_multiple_deps { -- 2.30.2